package com.atguigu.contorller;

import com.atguigu.entities.CommonResult;
import com.atguigu.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate template;

    private static final String URL = "http://127.0.0.1:8001";

    /**
     * RestTemplate通过json方式传输参数，接收方注意使用@requestbody接收装换
     * @param payment
     * @return
     */
    @RequestMapping("/consumer/payment/create")
    public CommonResult create(Payment payment){
        return template.postForObject(URL+"/payment/create",payment,CommonResult.class);
    }

    @RequestMapping("/consumer/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable long id){
        System.out.println("git远程添加测试");
        System.out.println("git远程添加测试2");
        System.out.println("git远程添加测试3");
        System.out.println("git远程添加测试4");
        return template.getForObject(URL+"/payment/get/"+id,CommonResult.class);
    }

}
